/**
 * Created by zlj on 2016/12/6.
 */
require('jquery');
require('layout/util');
var $form = require('js-path/formValide.js');
var $form2 = require('js-path/formValideNotSub.js');
var $alert = require('libs/alert');
$(function () {
    $('#channel_back').on('click',function () {
        window.history.go(-1);
    });
    $('#back').on('click',function () {
        window.history.go(-1);
    });
    judge();
});

//judge判断新增或更新
function judge() {
    var url =window.location.href;
    if(url.indexOf("id=")>0){
        var id = $.getUrlParam('id');
        load(id);
    }
}

//load
function load(id) {
    $.ajax({
        url:'api/v1/p/mms/internationalLogisticsProvider/detail',
        type:'post',
        data:{
            id:id
        },
        dataType:'json',
        success:function (result) {
            if (result.code == 200){
                $('#logistics_form').setForm(result.data);
                if(result.data.hasOcean =='Y'){
                    $("#logistics_form input[name=hasOcean]").attr("checked",true);
                    var myclass = $("#logistics_form input[name=hasOcean]").parent().attr('name')
                    $("#logistics_form input[name=hasOcean]").addClass('list-show');
                    $("."+myclass).show();
                    valideServiceType( $("#logistics_form input[name=hasOcean]"))
                    if(result.data.logisticsProviderOcean.minFeeWeight !=''){
                        $("#logistics_form input[name=biaozhunOcean]:eq(0)").attr("checked",'checked');
                    }else{
                        $("#logistics_form input[name=biaozhunOcean]:eq(1)").attr("checked",'checked');
                    }
                    $("#logistics_form input[name=minFeeWeightOcean]").val(result.data.logisticsProviderOcean.minFeeWeight);
                    $("#logistics_form input[name=minFeeVolumnOcean]").val(result.data.logisticsProviderOcean.minFeeVolumn);
                    $("#logistics_form input[name=minDiscountOcean]").val(result.data.logisticsProviderOcean.minDiscount);
                }
                if(result.data.hasAir =='Y'){
                    $("#logistics_form input[name=hasAir]").attr("checked",true);
                    var myclass = $("#logistics_form input[name=hasAir]").parent().attr('name')
                    $("#logistics_form input[name=hasAir]").addClass('list-show');
                    $("."+myclass).show();
                    valideServiceType( $("#logistics_form input[name=hasAir]"))
                    $("#logistics_form input[name=minFeeWeightAir]").val(result.data.logisticsProviderAir.minFeeWeight);
                    $("#logistics_form select[name=hasVolumnFeeAir]").val(result.data.logisticsProviderAir.hasVolumnFee);
                    $("#logistics_form input[name=volumnParamAir]").val(result.data.logisticsProviderAir.volumnParam);
                    $("#logistics_form input[name=minDiscountAir]").val(result.data.logisticsProviderAir.minDiscount);
                    $("#logistics_form select[name=hasBatteryAir]").val(result.data.logisticsProviderAir.hasBattery);
                    $("#logistics_form input[name=maxBoxWeightAir]").val(result.data.logisticsProviderAir.maxBoxWeight);
                    $("#logistics_form input[name=maxBoxLengthAir]").val(result.data.logisticsProviderAir.maxBoxLength);
                    $("#logistics_form input[name=maxInsureAmountAir]").val(result.data.logisticsProviderAir.maxInsureAmount);
                }
                if(result.data.hasRailway =='Y'){
                    $("#logistics_form input[name=hasRailway]").attr("checked",true);
                    var myclass = $("#logistics_form input[name=hasRailway]").parent().attr('name')
                    $("#logistics_form input[name=hasRailway]").addClass('list-show');
                    $("."+myclass).show();
                    valideServiceType( $("#logistics_form input[name=hasRailway]"))
                    $("#logistics_form input[name=minTransportationRailway]").val(result.data.logisticsProviderRailway.minTransportation);
                    $("#logistics_form input[name=minDiscountRailway]").val(result.data.logisticsProviderRailway.minDiscount);
                }
                if(result.data.hasExpress =='Y'){
                    $("#logistics_form input[name=hasExpress]").attr("checked",true);
                    var myclass = $("#logistics_form input[name=hasExpress]").parent().attr('name')
                    $("#logistics_form input[name=hasExpress]").addClass('list-show');
                    $("."+myclass).show();
                    valideServiceType( $("#logistics_form input[name=hasExpress]"))
                    $("#logistics_form input[name=minFeeWeightExpress]").val(result.data.logisticsProviderExpress.minFeeWeight);
                    $("#logistics_form select[name=hasVolumnFeeExpress]").val(result.data.logisticsProviderExpress.hasVolumnFee);
                    $("#logistics_form input[name=volumnParamExpress]").val(result.data.logisticsProviderExpress.volumnParam);
                    $("#logistics_form input[name=minDiscountExpress]").val(result.data.logisticsProviderExpress.minDiscount);
                    $("#logistics_form select[name=hasBatteryExpress]").val(result.data.logisticsProviderExpress.hasBattery);
                    $("#logistics_form input[name=maxBoxWeightExpress]").val(result.data.logisticsProviderExpress.maxBoxWeight);
                    $("#logistics_form input[name=maxBoxLengthExpress]").val(result.data.logisticsProviderExpress.maxBoxLength);
                    $("#logistics_form input[name=maxInsureAmountExpress]").val(result.data.logisticsProviderExpress.maxInsureAmount);
                    $("#logistics_form input[name=fuelAddFeeExpress]").val(result.data.logisticsProviderExpress.fuelAddFee);
                    $("#logistics_form input[name=remoteAddFeeExpress]").val(result.data.logisticsProviderExpress.remoteAddFee);

                }



            }else{
                $alert(result.message);
            }
        },
        error:function (e) {
            console.error('api/v1/p/mms/internationalLogisticsProvider/detail 接口调用失败 ' )
        }
    })
}
